#!/bin/bash
# OpenBMC Yocto环境初始化脚本
# 必须通过source执行以保持环境变量

set -e

OPENBMC_SOURCE="/workspace/data/openbmc_source"
BUILD_DIR="$OPENBMC_SOURCE/build"

echo "[INFO] 切换到OpenBMC源码目录..."
cd "$OPENBMC_SOURCE"

echo "[INFO] 初始化Yocto构建环境..."
# source setup脚本
source setup qemuarm

echo "[INFO] 当前构建目录: $PWD"
echo "[INFO] BUILDDIR=$BUILDDIR"

# 验证conf目录是否存在
if [ ! -d "conf" ]; then
    echo "[ERROR] conf目录不存在"
    exit 1
fi

echo "[INFO] 配置local.conf..."
cat >> conf/local.conf << 'EOFCONF'

# ============================================================================
# OpenBMC ABI分析工具 - 自定义配置
# ============================================================================

# 并行编译优化（根据容器资源调整）
BB_NUMBER_THREADS = "4"
PARALLEL_MAKE = "-j 4"

# 启用调试符号（用于ABI分析）
DEBUG_BUILD = "1"

# 启用共享状态缓存（加速后续编译）
SSTATE_DIR = "${TOPDIR}/sstate-cache"

# 保留源码和构建目录（便于提取库文件）
RM_WORK_EXCLUDE += "sdbusplus libpldm phosphor-logging phosphor-dbus-interfaces gpioplus stdplus"

# 日志配置
BBINCLUDELOGS = "yes"

# 设置下载目录（缓存）
DL_DIR = "${TOPDIR}/downloads"
EOFCONF

echo "[SUCCESS] Yocto环境配置完成！"
echo "[INFO] 配置文件: $PWD/conf/local.conf"

